import CryptoJS from "crypto-js";

let keyStr = "ATityu#UT98!24eX";
let ivStr = "ATityu#UT98!24eX";

// 加密
export function encryptAES(txt) {
  if(txt){
    let key = CryptoJS.enc.Utf8.parse(keyStr);
    let iv = CryptoJS.enc.Utf8.parse(ivStr);
    let sics = CryptoJS.enc.Utf8.parse(txt);

    let encrypted = CryptoJS.AES.encrypt(sics, key, {
      iv,
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString();
  }else{
    return txt
  }


}
// AES 解密方法
export function decryptAES(txt) {

  try {
    if(txt){
      let key = CryptoJS.enc.Utf8.parse(keyStr);
      let decrypt = CryptoJS.AES.decrypt(txt, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
      return CryptoJS.enc.Utf8.stringify(decrypt).toString();
    }else{
      return "";
    }
  }catch (e) {
    return txt
  }


}

// 电话号码隐藏
export function phoneNumberDesc(phone){
  if (phone) {
    return  phone.replace(/^(.{3})(?:\w+)(.{4})$/, "\$1****\$2");
  }else{
    return ''
  }
}

